package com.example.hotfixdemo;
import android.content.Context;
import android.support.annotation.Keep;
import android.util.Log;

import com.taobao.sophix.PatchStatus;
import com.taobao.sophix.SophixApplication;
import com.taobao.sophix.SophixEntry;
import com.taobao.sophix.SophixManager;
import com.taobao.sophix.listener.PatchLoadStatusListener;
/**
 * Sophix入口类，专门用于初始化Sophix，不应包含任何业务逻辑。
 * 此类必须继承自SophixApplication，onCreate方法不需要实现。
 * 此类不应与项目中的其他类有任何互相调用的逻辑，必须完全做到隔离。
 * AndroidManifest中设置application为此类，而SophixEntry中设为原先Application类。
 * 注意原先Application里不需要再重复初始化Sophix，并且需要避免混淆原先Application类。
 * 如有其它自定义改造，请咨询官方后妥善处理。
 */
public class SophixStubApplication extends SophixApplication {
    private final String TAG = "SophixStubApplication";
    // 此处SophixEntry应指定真正的Application，并且保证RealApplicationStub类名不被混淆。
    @Keep
    @SophixEntry(MyRealApplication.class)
    static class RealApplicationStub {}
    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
//         如果需要使用MultiDex，需要在此处调用。
//         MultiDex.install(this);
        initSophix();
    }
    private void initSophix() {
        String appVersion = "0.0.0";
        try {
            appVersion = this.getPackageManager()
                    .getPackageInfo(this.getPackageName(), 0)
                    .versionName;
        } catch (Exception e) {
        }
        final SophixManager instance = SophixManager.getInstance();
        instance.setContext(this)
                .setAppVersion(appVersion)
                .setSecretMetaData("27956173-1", "9dc73f24245f0e18ce836c56ab938cfb", "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCQMepvVXv+VNUSIYBKH3LGCbgWquSg+95ASTnoDlnhJGf0YfybQCpeK0Pr/Mn0Hk7Zlr15FEtiACyvOllRDfWhOtU68gEXeTuZ5C00wSWxhJ8SFsM54UV8PiMO1oBNOdDKVPAfaVADEUd+V9UcOZoMy80M6RsQdqhwX9RxLFEdovjqmB4yGOWZ+ppClJ3pa2S/mbsxOYsJzCqG8KZq5aLLqtBsvHJ+Cw7p6x3Z6e8JV0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KlrciNTFWTgaauUrogQPa/avVkFkbzP9cWBTJSwlguYX1IOITwpb183580hlAg9uDhmlfdTBTguas1mMJAoGAOqe35gR8GtRXFObAdfGdz/p7+rfNjkCUv+0L1CL7G+lGH45+QjrTJhuLL43lDJL3oTZe96g3tOHklTwCkxQf59KdlXQrw4S8L54LuqOvEbZGl8zOw2Eq3qUygTeSXUQ7Az7rtbSLIF4hnOGgMhyuS4KQpYYf1FRpuBHTRrsXwws=")
                .setEnableDebug(true)
                .setEnableFullLog()
                .setPatchLoadStatusStub(new PatchLoadStatusListener() {
                    @Override
                    public void onLoad(final int mode, final int code, final String info, final int handlePatchVersion) {
                        if (code == PatchStatus.CODE_LOAD_SUCCESS) {
                            Log.i(TAG, "sophix load patch success!");
                        } else if (code == PatchStatus.CODE_LOAD_RELAUNCH) {
                            // 如果需要在后台重启，建议此处用SharePreference保存状态。
                            Log.i(TAG, "sophix preload patch success. restart app to make effect.");
                        }
                    }
                }).initialize();
    }
}